import { defineStore } from 'pinia';

interface IColumns {
  columnCode: string
  columnDataType: string
  columnName: string
  columnType: number | string
}

interface Itemplate {
  autoAnalysis: number
  code: string
  id: number | string
  name: string
  startLine: number
  suitability: string
  importColumns: IColumns[]
}

interface Iproperties {
  id: string | number
  name: string
  value: string
  typeCode: string
}

interface IHotData {
  index: string | number
  name: string
  properties: Iproperties[]
  template: Itemplate
}

const useTplInfoStore = defineStore('tplInfo', {
  state: () => {
    return {
      hotData: [],
    }
  },
  actions: {
    // 给hotData赋值
    sethotData(alldata: IHotData[]) {
      (this.hotData as any) = alldata
    },
    // 修改数据起始行
    changeCurStartLine(curActive:number,val:number) {
      (this.hotData[curActive]['template']['startLine'] as any) = val
    },
    // 修改多sheet页共享、自动分析
    changeCheckbox(curActive:number,val:any[]) {
      // 多sheet页共享 用不上，不需要传给后端
      // (this.hotData[curActive]['template']['sheetsShare'] as any) = (val.some(item => item == 'sheetsShare')) ? 1 : 0;
      // 自动分析
      (this.hotData[curActive]['template']['autoAnalysis'] as any) = (val.some(item => item == 'autoAnalysis')) ? 1 : 0;
    }
  }
})

export default useTplInfoStore;